package o2o.config.jms.listener;

import com.jinyouapp.common.tools.jms.model.JMSNotify;
import o2o.config.jms.convert.NotifyMessageConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

@Component
public class QueueMessageListener implements MessageListener {
    
    @Autowired
    private NotifyMessageConverter messageConverter;

    private static Logger logger = LoggerFactory.getLogger(QueueMessageListener.class);

    /**
     * 接收消息
     */
    public void onMessage(Message message) {
        // TODO Auto-generated method stub
        try {
            ObjectMessage objectMessage = (ObjectMessage) message;
            JMSNotify noticeInfo = (JMSNotify) messageConverter.fromMessage(objectMessage);

//			System.out.println("queue收到消息" + noticeInfo.getContent());

        } catch (Exception e) {
            // TODO: handle exception
            logger.error("处理信息时发生异常", e);
        }
    }

    public NotifyMessageConverter getMessageConverter() {
        return messageConverter;
    }

    public void setMessageConverter(NotifyMessageConverter messageConverter) {
        this.messageConverter = messageConverter;
    }
}
